//
//  GLRightMenuController.m
//  GLSliderView
//
//  Created by 张国梁 on 15/11/28.
//  Copyright © 2015年 CoderGL. All rights reserved.
//

#import "GLRightMenuController.h"

#import "GLRightTopView.h"
#import "GLBottomView.h"

@interface GLRightMenuController ()
@property (nonatomic, weak) GLRightTopView *topView;
@property (nonatomic, weak) GLBottomView *bottomView;

@end

@implementation GLRightMenuController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 设置顶部内容
    [self setupTopContent];
    
    // 设置中间内容
    [self setupMiddleContent];
    
    // 设置底部内容
    [self setupBottomContent];
}

- (void)setupTopContent {
    GLRightTopView *topView = [[[NSBundle mainBundle] loadNibNamed:@"GLRightTopView" owner:self options:nil] firstObject];
    [self.view addSubview:topView];
    self.topView = topView;
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    self.topView.width = self.view.width;
}


- (void)setupMiddleContent {
    for (int i = 0; i < 3; i++) {
        UIView *middleView = [[[NSBundle mainBundle] loadNibNamed:@"GLMiddleView" owner:self options:nil] firstObject];
        middleView.width = self.view.width;
        middleView.y = CGRectGetMaxY(self.topView.frame) + i * middleView.height;
        [self.view addSubview:middleView];
    }
}

- (void)setupBottomContent {
    GLBottomView *bottom = [GLBottomView new];
    bottom.frame = CGRectMake(0, CGRectGetMaxY(self.view.subviews.lastObject.frame), self.view.width, 300);
    [self.view addSubview:bottom];
    self.bottomView = bottom;
    
}


- (void)didShow {
    
    // 转场动画
    [UIView transitionWithView:self.topView.iconView duration:1.0 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
        self.topView.iconView.image = [UIImage imageNamed:@"user_defaultgift"];
    } completion:^(BOOL finished) {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
           [UIView transitionWithView:self.topView.iconView duration:1.0 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
               self.topView.iconView.image = [UIImage imageNamed:@"default_avatar"];
           } completion:nil];
        });
    }];
    
}


@end
